﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OAuth;
using System.Web;
using System.Windows.Controls;

namespace FBApp.Classes
{
    class FBAuthentication
    {
        private static string appID = "158338277521942";
        private string consumerSecret = "34be6fa8a7a61a58b488a54967f02779";
        private Uri uri = new Uri("https://graph.facebook.com/oauth/access_token");
        
        private string expires = "";

        public FBAuthentication()
        {
        }

        public static string getAppID()
        {
            return appID;
        }

        public void oAuth()
        {
            OAuthBase oAuth = new OAuthBase();
            string nonce = oAuth.GenerateNonce();
            string timeStamp = oAuth.GenerateTimeStamp();
            string signature,url, url2;
            signature = oAuth.GenerateSignature(uri, appID, consumerSecret, string.Empty, string.Empty, "GET", timeStamp, nonce, out url, out url2);

            signature = HttpUtility.UrlEncode(signature);

            StringBuilder sb = new StringBuilder(uri.ToString());
            sb.AppendFormat("");

            System.Windows.MessageBox.Show(url);
            System.Windows.MessageBox.Show(url2);
            System.Windows.MessageBox.Show(signature);
        }

        public string webAuthenticate(string url)
        {
            string[] reply = url.Split('#');
            string[] reply2 = reply[1].Split('&');

            string token = reply2[0].Split('=')[1];
            expires = reply2[1].Split('=')[1];
            return token;                                                  
        }
    }
}
